package web

import (
	http "github.com/valyala/fasthttp"

	"xp/lib/mux"
)

func ErrorPage(m map[int]string) mux.Middleware {
	return func(next mux.Handler) mux.Handler {
		return func(ctx *mux.Ctx) {
			next(ctx)
			code := ctx.Response.StatusCode()
			if code < 400 {
				return
			}
			if page, ok := m[code]; ok {
				ctx.Response.Header.Set("Cache-Control", "no-cache, no-store, must-revalidate")
				http.ServeFileUncompressed(ctx.RequestCtx, page)
			}
		}
	}
}
